﻿@model QRCodePass.Mvc.ViewModels.Departments.DepartmentListModel

@{
    ViewBag.Title = "院系列表页面";
}
<h1>院系列表</h1>
<form asp-action="Index" method="get">

    <div class="form-actions no-color">
        <input type="hidden" name="CurrentPage" value="@Model.Department.CurrentPage" />
        <input type="hidden" name="Sorting" value="@Model.Department.Sorting" />
        <p>
            请输入名称: <input type="text" name="FilterText" value="@Model.Department.FilterText" />
            <input type="submit" value="查询" class="btn btn-outline-dark" /> |
            <a asp-action="Index">返回所有列表</a>| <a asp-action="Create">
                添加
            </a>
        </p>
    </div>
</form>

<div class="  table-responsive-sm">
    @if (Model.Department.Data.Any())
    {
        <table class="table table-bordered table-striped">
            <thead>
            <tr>

                <th scope="col" class="sort-link">
                    <a asp-action="Index"
                       asp-route-Sorting="Name" asp-route-CurrentPage="@Model.Department.CurrentPage" asp-route-FilterText="@Model.Department.FilterText">
                        院系名称
                    </a>
                </th>
                @*<th>
                            <a asp-action="Index" asp-route-Sorting="StartDate " asp-route-CurrentPage="@Model.CurrentPage" asp-route-FilterText="@Model.FilterText">
                                成立时间
                            </a>
                        </th>
                        <th>
                            <a asp-action="Index" asp-route-Sorting="Budget " asp-route-CurrentPage="@Model.CurrentPage" asp-route-FilterText="@Model.FilterText">
                                预算
                            </a>
                        </th>
                        <th>负责人</th>*@
                <th scope="col">操作</th>
            </tr>
            </thead>
            <tbody>

            @foreach (var item in Model.Department.Data)
            {
                string selectedRow = "";
                if (item.Id == Model.SelectedId)
                {
                    selectedRow = "table-success";
                }
                <tr class="@selectedRow">
                    <td>@item.Name</td>
                    @*<td> @Html.DisplayFor(modelItem => item.StartDate) </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Budget)
                            </td>
                            <td>@item.Administrator.Name</td>*@
                    <td>
                        <form method="post" asp-action="Delete" asp-route-id="@item.Id">
                            <a asp-controller="Departments" class="btn btn-info"  asp-route-Sorting="@Model.Department.Sorting" asp-route-CurrentPage="@Model.Department.CurrentPage" asp-action="Index" asp-route-id="@item.Id">查看</a>
                            <a asp-controller="Departments" asp-action="Edit" asp-route-Id="@item.Id" class="btn btn-primary m-1">编辑</a>
                            <span id="confirmDeleteSpan_@item.Id" style="display: none">
                                <span>你确定你要删除?</span>
                                <button type="submit" class="btn btn-danger">是</button>
                                <a href="#" class="btn btn-primary" onclick="confirmDelete('@item.Id', false)">否</a>
                            </span>
                            <span id="deleteSpan_@item.Id">
                                <a href="#" class="btn btn-danger" onclick="confirmDelete('@item.Id', true)">删除</a>
                            </span>
                        </form>
                    </td>
                </tr>
            }

            </tbody>
        </table>
        <div class="mt-2 mb-4">
        @if (Model.Processes != null)
        {

            if (Model.Processes.Count > 0)
            {
                <div class="card mb-3">

                    <div class="card-header">
                        系部绑定的的流程列表
                    </div>

                    <div class="card-body">
                        <table class="table">
                            <tr>

                                <th>流程编号</th>
                                <th>流程名称</th>
                                @*<th>系部</th>*@
                                <th>前置任务</th>
                                @*<th>操作</th>*@
                            </tr>

                            @foreach (var item in Model.Processes)
                            {
                                <tr>

                                    <td>
                                        @item.Id
                                    </td>
                                    <td>
                                        @item.ProcName
                                    </td>
                                    @*<td>
                                       @Model.Build.Data.Find(x => x.Id == item.BuildId)?.Name
                                    </td>*@
                                    <td>
                                        @Model.Processes.Find(x => x.Id == item.PreTask)?.ProcName
                                    </td>
                                    @*<td>
                                        <a asp-controller="Builds" class="btn btn-info" asp-action="Index" asp-route-Sorting="@Model.Build.Sorting" asp-route-CurrentPage="@Model.Build.CurrentPage" asp-route-Id="@item.BuildId">查看</a>
                                    </td>*@
                                </tr>
                            }
                        </table>
                    </div>
                </div>

            }
            else
            {
                <div class="card mb-3">

                    <div class="card-header">
                        该系部还未分配流程
                    </div>
                </div>

            }

        }
        </div>
    }

    @await Html.PartialAsync("_Pagination", Model.Department)
</div>

@section Scripts {
    <script src="~/js/CustomScript.js" asp-append-version="true"></script>
}